class graph():


    class Node() :
        def __init__(self, locationId, name, X, Y):
            self.locationId = locationId
            self.name = name
            self.X = X
            self.Y = Y
    

    class Link() :
        def __init__(self, id, firstlocation, secondlocation):
            self.id = id
            self.firstlocation = firstlocation
            self.secondlocation = secondlocation

    
    nodelist = []

    def readfromLocation(self):
       f = open('locations.csv' , 'r') 
       temp = f.read()
       temp = temp.split('\n')
       temp.pop(0)
       temp.pop(-1)
       for i in temp:
           temp = i.split(';')
           self.nodelist.append(temp)
           temp= self.Node()
            
       

       f.close()

    linklist = []

    def readfromLinks(self):
        ff = open('links.csv' , 'r') 
        temp = ff.read()
        temp = temp.split('\n')
        temp.pop(0)
        temp.pop(-1)
        for i in temp:
            temp = i.split(';')
            self.linklist.append(temp)
            temp = self.Link()
            for node in self.nodelist:
                if temp.firstlocation == node.id:
                    node.linklist.append(temp)
                elif temp.secondlocation == node.id:
                    node.linklist.append(temp)
        ff.close()

    
    

    def getNode(self, name):
        for n in self.nodelist:
            if(name == n.name):
                print(n)


    #def getLocation(self, link):
    #    mylist = []
    
    
        
    def getAllLinkFrom(self, node) : 
        mylist = []
        for l in self.linklist:
            mylist.append(l)
            print(l)
            return mylist
        
          
    


    def getsuccessers(self, node):
        mylist1 = []
        
        for l in self.linklist:
            if(l.firstlocation == self.nodelist.locationId):
                mylist1.append(l.secondlocation)
            if (l.secondlocation == self.nodelist.locationId):
                mylist1.append(l.firstlocation)
            
        return mylist1



    def paths(self, start, goal):
        
        frontier = [[start]]
        while frontier != []:
            cpath = frontier.pop(0)
            s = cpath[-1]
            print(s)
            if(s == goal):
                return cpath
            for next in self.getsuccessers(s):
                frontier.append(cpath + [s])
            



    #def pathss(self, start, end):

    ## maintain a queue of paths
    #    queue = []
    ## push the first path into the queue
    #    queue.append([start])
    #    visited = [start]
    #    while queue:
    #    # get the first path from the queue
    #        path = queue.pop(0)
    #    # get the last node from the path
    #        node = path[-1]
    #        visited.append(node)
    #        print(node)
    #    # path found
    #        if (node == end):
    #            return print(path)
    #    # enumerate all adjacent nodes, construct a new path and push it into the queue
    #        for next in self.getsuccessers(node):
    #            if next not in queue:
    #                queue.append(path + [next])
    #    return queue

    

   


   

        
        









g = graph()
g.readfromLocation()
g.readfromLinks()

#g.getNode("Sorby")
#g.getLocation("829304708")
#g.getAllLinkFrom("Sorby")
#g.getsuccessers("Central Orebro")
g.pathss("Brickebacken", "Central Orebro")
